﻿<UserControl x:Class="MathematicallySafe.HeadCounter.Views.RaidsView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Common="clr-namespace:MathematicallySafe.HeadCounter.Common" 
    xmlns:behaviours="clr-namespace:AttachedCommandBehavior;assembly=AttachedCommandBehavior" 
    xmlns:System="clr-namespace:System;assembly=mscorlib"             
    Initialized="RaidsViewInitialized">
    
    <UserControl.Resources>

        <Style x:Key="DropTargetItem" TargetType="{x:Type FrameworkElement}" >
            <Setter Property="behaviours:CommandBehavior.Event" Value="Drop" />
            <Setter Property="behaviours:CommandBehavior.Command" Value="{Binding Path=DropCommand}" />
            <Setter Property="behaviours:CommandBehavior.CommandParameter" Value="{Binding}" />
        </Style>

        <Style x:Key="DropTargetListViewItem" TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource ListViewItemStyle}">
            <Setter Property="behaviours:CommandBehavior.Event" Value="Drop" />
            <Setter Property="behaviours:CommandBehavior.Command" Value="{Binding Path=DropCommand}" />
            <Setter Property="behaviours:CommandBehavior.CommandParameter" Value="{Binding}" />
        </Style>

        <DataTemplate x:Key="ShortLootItemTemplate" DataType="Models:LootItem">
            <TextBlock Margin="0,0,4,0" Text="{Binding Path=ItemName}" Foreground="{StaticResource EpicItemColour}" FontWeight="Bold"/>
        </DataTemplate>
        
        <DataTemplate x:Key="LootItemTemplate" DataType="Models:LootItem">
            <Grid Width="250" Margin="4" TextElement.Foreground="{StaticResource DefaultForeground}" TextElement.FontSize="14">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

                <TextBlock Grid.Row="0" Grid.Column="0" Text="{Binding Path=ItemName}" Foreground="{StaticResource EpicItemColour}" FontWeight="Bold"/>
                <TextBlock Grid.Row="1" Grid.Column="0" Text="{Binding Path=Winner}" />
                
                <StackPanel Grid.Row="2" Grid.Column="0" Orientation="Horizontal" TextElement.FontSize="12" TextElement.FontWeight="Normal">
                    <TextBlock Text="{Binding Path=Item.Boss}" />
                    <TextBlock Text="{Binding Path=Item.Slot, StringFormat=\, {0}, Converter={StaticResource EnumDescriptionConverter}}" />
                    <TextBlock Text="{Binding Path=Item.SubClass, StringFormat=\, {0}, Converter={StaticResource EnumDescriptionConverter}}" />
                </StackPanel>
                
                <TextBlock Grid.Row="3" Grid.Column="0" Text="{Binding Path=LootValueCalulation}" FontSize="12" FontWeight="Normal" />
                
                <Grid.ToolTip>
                    <ToolTip Content="{Binding Path=Item}" Style="{StaticResource ItemTooltipTemplate}" />        
                </Grid.ToolTip>
                    
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="AttendedCellTemplate">
            <ToggleButton IsChecked="{Binding Attended}" Width="40" Command="{Binding ToggleAttendedCommand}">
                <ToggleButton.Style>
                    <Style TargetType="{x:Type ToggleButton}">
                        <Setter Property="Content" Value="No"/>
                        <Style.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter Property="Content" Value="Yes"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ToggleButton.Style>
            </ToggleButton>
        </DataTemplate>

    </UserControl.Resources>
    
    <Grid Style="{StaticResource TabContainer}">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="275" />
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <ListView Name="listViewRaids" Grid.Row="1" Grid.Column="0" 
                  ItemContainerStyle="{StaticResource ListViewItemStyle}" ItemsSource="{Binding Path=Raids}" SelectedItem="{Binding SelectedRaid}" >
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="NaN" CellTemplate="{StaticResource RaidDateCellTemplate}" Header="DATE"/>
                    <GridViewColumn Width="NaN" CellTemplate="{StaticResource RaidZoneCellTemplate}" Header="ZONE"/>
                </GridView>
            </ListView.View>
        </ListView>

        <ScrollViewer Grid.Row="1" Grid.Column="1" Grid.RowSpan="1" VerticalScrollBarVisibility="Auto" Margin="8,0">
            <ItemsControl Name="listViewLoot" 
                          Common:DragDropManager.IsDragSource="True" Common:DragDropManager.DragDropTemplate="{StaticResource LootDragTemplate}"
                          Style="{StaticResource WrappingItemsPanel}" 
                          ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible"
                          Visibility="{Binding ElementName=listViewRaids, Path=SelectedItem, Converter={StaticResource HiddenIfNull}}"
                          DataContext="{Binding ElementName=listViewRaids, Path=SelectedItem}"
                          ItemsSource="{Binding Path=LootView}" ItemTemplate="{StaticResource LootItemTemplate}">
                </ItemsControl>
        </ScrollViewer>

        <TabControl Grid.Row="1" Grid.Column="2" Grid.RowSpan="2" Style="{StaticResource SubTabControl}">
            <TabItem Header="RAIDERS" Style="{StaticResource MainTabControlItem}">
                <ListView Name="listViewRaidMembers" Common:DragDropManager.IsDropTarget="True" 
                          MaxWidth="260" Margin="-12,-20,0,0"
                          Background="#f5f5f5"
                          Visibility="{Binding ElementName=listViewRaids, Path=SelectedItem, Converter={StaticResource HiddenIfNull}}"
                          DataContext="{Binding ElementName=listViewRaids, Path=SelectedItem}"
                          ItemContainerStyle="{StaticResource DropTargetListViewItem}" ItemsSource="{Binding Path=RaidMembersView}" 
                          SelectedValue="{Binding SelectedRaider}" SelectedValuePath="Name">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Width="NaN" CellTemplate="{StaticResource BasicRaiderNameCellTemplate}" Header="RAIDER"/>
                            <GridViewColumn Width="60" CellTemplate="{StaticResource LootWonCellTemplate}" Header="LOOT" />
                            <GridViewColumn Width="60" CellTemplate="{StaticResource MinutesCellTemplate}" Header="MINS" />
                        </GridView>
                    </ListView.View>
                </ListView>
            </TabItem>
            <TabItem Header="EXTRA ATTENDANCE" Style="{StaticResource MainTabControlItem}">
                <ListView Name="listViewRaidExtraMembers" MaxWidth="260" Margin="-12,-20,0,0" Background="#f5f5f5"
                          Visibility="{Binding ElementName=listViewRaids, Path=SelectedItem, Converter={StaticResource HiddenIfNull}}"
                          DataContext="{Binding ElementName=listViewRaids, Path=SelectedItem}"
                          ItemContainerStyle="{StaticResource DropTargetListViewItem}" ItemsSource="{Binding Path=NonRaidersView}" 
                          SelectedValue="{Binding SelectedRaider}" SelectedValuePath="Name">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Width="150" CellTemplate="{StaticResource BasicRaiderNameCellTemplate}" Header="RAIDER"/>
                            <GridViewColumn Width="90" CellTemplate="{StaticResource AttendedCellTemplate}" Header="ATTENDED"/>
                        </GridView>
                    </ListView.View>
                </ListView>
            </TabItem>
        </TabControl>

        <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Margin="0" DataContext="{Binding ElementName=listViewRaids, Path=SelectedItem}" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <StackPanel Grid.Column="0" Margin="4">
                <Image Width="32" Height="32" Source="/Resources/disenchant.jpg" 
                        Common:DragDropManager.IsDropTarget="True" 
                        behaviours:CommandBehavior.Event="Drop" behaviours:CommandBehavior.Command="{Binding Path=AlterOutomeCommand}" 
                        behaviours:CommandBehavior.CommandParameter="Disenchanted">
                    <Image.ToolTip>
                        Drop disenchanted items here
                    </Image.ToolTip>
                </Image>
            </StackPanel>

            <StackPanel Grid.Column="1" Margin="4" >
                <Image Width="32" Height="32" Source="/Resources/offspec.jpg" 
                        Common:DragDropManager.IsDropTarget="True" 
                        behaviours:CommandBehavior.Event="Drop" behaviours:CommandBehavior.Command="{Binding Path=AlterOutomeCommand}" 
                        behaviours:CommandBehavior.CommandParameter="Offspec">
                    <Image.ToolTip>
                        Drop offspec items here. Offspec items do not count in loot metrics
                    </Image.ToolTip>
                </Image>
            </StackPanel>

            <StackPanel Grid.Column="2" Margin="4" >
                <Image Width="32" Height="32" Source="/Resources/bank.jpg" 
                        Common:DragDropManager.IsDropTarget="True" 
                        behaviours:CommandBehavior.Event="Drop" behaviours:CommandBehavior.Command="{Binding Path=AlterOutomeCommand}" 
                        behaviours:CommandBehavior.CommandParameter="Banked">
                    <Image.ToolTip>
                        Drop banked/boe items here
                    </Image.ToolTip>
                </Image>
            </StackPanel>

            <ItemsControl Grid.Column="3" 
                          Style="{StaticResource WrappingItemsPanel}" 
                          Common:DragDropManager.IsDragSource="True" Common:DragDropManager.DragDropTemplate="{StaticResource LootDragTemplate}"
                          ItemsSource="{Binding Path=UnassignedLootView}" ItemTemplate="{StaticResource ShortLootItemTemplate}"/>

            <TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" Text="{Binding UnassignedLootSummary}" />
        </Grid>
        
    </Grid>
</UserControl>
